//
//  LYQMineActivityManageViewController.m
//  ZCProject
//
//  Created by Zheng on 2016/12/22.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQMineActivityManageViewController.h"

#import "LYQActivityListSelectedView.h"
#import "LYQActivityManageInfoCell.h"
#import "LYQActivityManageFooterCell.h"

#define kLYQActivityManageInfoCell_ID1 @"kLYQActivityManageInfoCell_ID1"
#define kLYQActivityManageInfoCell_ID2 @"kLYQActivityManageInfoCell_ID2"
#define kLYQActivityManageFooterCell_ID1 @"kLYQActivityManageFooterCell_ID1"
#define kLYQActivityManageFooterCell_ID2 @"kLYQActivityManageFooterCell_ID2"

@interface LYQMineActivityManageViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) LYQActivityListSelectedView *selectedView;

@property (nonatomic, assign) LYQActivityManageInfoCellStyle cellStyle;
@property (nonatomic, copy) NSString *cellInfoIdentifier;

@property (nonatomic, assign) LYQActivityManageFooterCellStyle footerCellStyle;
@property (nonatomic, copy) NSString *footerIdentifier;

@end

@implementation LYQMineActivityManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"我的活动";
    
    _cellInfoIdentifier = kLYQActivityManageInfoCell_ID1;
    _cellStyle = LYQActivityManageInfoCellStyleRelease;
    
    _footerIdentifier = kLYQActivityManageFooterCell_ID1;
    _footerCellStyle = LYQActivityManageFooterCellStyleRelease;
    
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    
    [self.view addSubview:self.selectedView];
    
    [self selectedTypeAction];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [_selectedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.equalTo(@(kWScale(50)));
    }];
    
    [self.listTableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.left.bottom.equalTo(self.view);
        make.top.equalTo(self.view).offset(kWScale(50));
    }];
}

#pragma mark - lazy load subviews
- (LYQActivityListSelectedView *)selectedView {
    if (_selectedView) {
        return _selectedView;
    }
    
    _selectedView = [[LYQActivityListSelectedView alloc] init];
    
    return _selectedView;
}

#pragma mark - tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        LYQActivityManageInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:_cellInfoIdentifier];
        if (!cell) {
            cell = [[LYQActivityManageInfoCell alloc] initWithStyle:_cellStyle reuseIdentifier:_cellInfoIdentifier];
        }
        
        NSArray *titlesArr;
        
        if (_cellStyle == LYQActivityManageInfoCellStyleRelease) {
             titlesArr = @[@"中国出境旅游交易会",
                           @"中国出境旅游交易会,CITM上海2016,虹桥机场专车接送",
                           @"中国出境旅游交易会,CITM上海2016",
                           @"旅游交易会"];
        } else {
            titlesArr = @[@"中国出境旅游交易会,CITM上海2016,虹桥机场专车接送",
                          @"中国出境旅游交易会",
                          @"中国出境旅游交易会,CITM上海2016",
                          @"旅游交易会"];
        }
        

        cell.titleLbl.text = titlesArr[indexPath.section];
        
        return cell;
    } else {
        LYQActivityManageFooterCell *cell = [tableView dequeueReusableCellWithIdentifier:_footerIdentifier];
        if (!cell) {
            cell = [[LYQActivityManageFooterCell alloc] initWithStyle:_footerCellStyle reuseIdentifier:_footerIdentifier];
        }
        
        return cell;
    }
    
}

#pragma mark - tableview delegate
#pragma mark 单元格高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return kWScale(95);
    } else {
        return kWScale(45);
    }
}

#pragma mark 头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kWScale(10);
}

#pragma mark 尾视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}

#pragma mark 设置分割线偏移量
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}

#pragma mark - 发布或参与的活动 点击事件
- (void)selectedTypeAction {
    [_selectedView chooseButtonTypeWithChooseBlock:^(NSInteger index) {
        
        if (index == 0) {
            NSLog(@"发布的活动");
            
            _cellStyle = LYQActivityManageInfoCellStyleRelease;
            _cellInfoIdentifier = kLYQActivityManageInfoCell_ID1;
            
            _footerCellStyle = LYQActivityManageFooterCellStyleRelease;
            _footerIdentifier = kLYQActivityManageFooterCell_ID1;
            
        } else {
            NSLog(@"参与的活动");
        
            _cellStyle = LYQActivityManageInfoCellStyleParticipate;
            _cellInfoIdentifier = kLYQActivityManageInfoCell_ID2;
            
            _footerCellStyle = LYQActivityManageFooterCellStyleParticipate;
            _footerIdentifier = kLYQActivityManageFooterCell_ID2;
        }
        
        [self.listTableView reloadData];
        
    }];
}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
